{extend name="public/base"}

{block name="title"}
开摩邦网-维修端
{/block}

{block name="style"}
{css href="/static/wechat/css/index.css" /}
{css href="/static/wechat/popo/css/index_map.css" /}
<style type="text/css">
    .map_home1{position:fixed;bottom:10px;border:none;}
</style>
{/block}

{block name="body"}
<div class="pageControl index">
    <div class="nav">
        <div class="msui_navTop">
            <a class="msui_navTop-back" href="/wechat/r_store/"><i class="micon-home"></i></a>
            <h1 class="msui_navTop-title">{$data.repair_name}</h1>
            <a class="msui_navTop-icon" href="{:url('w_message/index', ['type' => 1])}">
                {gt name="$data.new_msg_num|default=0" value="0"}
                <i class="to_messages_png"></i>
                {else /}
                <i class="micon-message2"></i>
                {/gt}
                <span class="weui-badge weui-badge_dot"></span>
            </a>
        </div>
        <div class="weui-form-preview1">
            <div class="weui-form-preview__bd1">
                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label"><span class="cl-f fs07">今日收入(元)</span></label>
                    <span class="weui-form-preview__value"><span class="cl-f fs07">店铺评分 : <span>{$data.level_avg|default='5.0'}</span></span></span>
                </div>
                <div class="weui-form-preview__item">
                    <a class="weui-form-preview__label " style="width:100%;text-align:left;" href="{:url('r_wallet/detail_today',['type'=>1])}"><span class="fs22 cl-f">{$data.order_price_sum|default='0.00'}</span></a>
                    <span class="weui-form-preview__value"></span>
                </div>
            </div>
        </div>
        <div class="msui_top">
            <div class="msui_top_a">
                <a class="msui_top_price" href="{:url('w_distribution/index',['type'=>1])}" >
                    <p>累计分销收益</p>
                    <p>￥<span>{$data.distribution_money_all|default='0.00'}</span></p>
                </a>
                <a class="msui_top_count" href="{:url('r_orders/index_today',['status'=>100])}" >
                    <p>今日订单</p>
                    <p>{$data.order_count|default='0'}</p>
                </a>
            </div>
        </div>
    </div>

    <div id="box_orders">
        <!--<div class="msui_table msui_tableCom">-->
            <!--<a class="msui_tabCell-img msui_tableImg-circle" href="javascript:;">-->
                <!--<img src="/static/wechat/images/2.jpg">-->
            <!--</a>-->
            <!--<div class="msui_tabCell-content">-->
                <!--<p class="fs085 cl-3333">[维修]轮胎破了</p>-->
                <!--<p class="fs075 cl-6666">思明区前埔东路588号</p>-->
                <!--<div>-->
                    <!--<span class="weui-badge weui-badge_bd">距离约 284m</span>-->
                    <!--<p class="msui_date">-->
                        <!--<span class="cl-9999">12月20日</span>-->
                        <!--<span class="cl-9999"> 20:16:56</span>-->
                    <!--</p>-->
                <!--</div>-->
            <!--</div>-->
            <!--<a class="msui_tabCell-button">-->
                <!--<i class="micon-in"></i>-->
            <!--</a>-->
        <!--</div>-->
    </div>

    <p class="map_b map_home1">
            <span class="map_b_bd3">
                <img src="/static/wechat/images/small_03.png" alt=""/>
            </span>
    </p>

</div>

<!-- loading toast -->
<div id="loadingToast" style="display:none;">
    <div class="weui-mask_transparent"></div>
    <div class="weui-toast" style="opacity: 1; visibility: visible;">
        <i class="weui-loading weui-icon_toast"></i>
        <p class="weui-toast__content">加载中...</p>
    </div>
</div>

{/block}
{block name="javascript"}

<script>

    $(function () {

        $('.map_home1').click(function(){
            var tmpUrl = '{:url("index_map")}';
            window.location.href = tmpUrl;
        });

        var obj = {
            'is_more' : true,
            'page' : 1,
            'url' : '{:url("get_orders")}',
            'status' : 1
        };
        get_order_list();
        $(window).scroll( function() {
            if (($(document).height() - $(this).scrollTop() - $(this).height()<50) && obj.is_more){
                get_order_list();
            }
        });

        $(document).on('click', '.msui_tableCom', function () {
            var tmpUrl = '{:url("order_info")}?id='+$(this).attr('order_id');
            window.location.href = tmpUrl;
        });

        function get_order_list() {
            $('#loadingToast').fadeIn(100);
            obj.is_more = false;
            $.ajax({
                type : 'POST',
                url : obj.url + '?page=' + obj.page,
                data : {
                    status : obj.status
                },
                dataType : 'json',
                success : function (msg) {
                    $('#loadingToast').fadeOut(100);
                    if(msg.code!=200){
                        var code = msg.code;
                        $.alert(error_code[code]);
                        return false;
                    }
                    var orders = msg.data.data; // 订单数据
                    var len = orders.length; //
                    var html = [];
                    var my_lat = parseFloat('{$data.lat}');
                    var my_lng = parseFloat('{$data.lon}');

                    for (var i = 0; i < len; i++) {
                        var dataOrder = i+1;
                        var orders_headimgurl = orders[i].headimgurl.indexOf("://")!=-1?orders[i].headimgurl:SCOPE.image_host_url+orders[i].headimgurl;
                        if( !orders[i].headimgurl ){
                            orders_headimgurl = "/static/wechat/images/tui_03.jpg";
                        }
                        var h = '<a class="msui_table msui_tableCom" order_id="'+orders[i].id+'" href="javascript:;">' +
                                '<span class="msui_tabCell-img msui_tableImg-circle">' +
                                '    <img src="'+orders_headimgurl+'" src1="'+orders[i].headimgurl+'"  />' +
                                '</span>' +
                                '<div class="msui_tabCell-content">' +
                                '<p class="fs085 cl-3333">['+orders[i].item_name+']'+orders[i].msg+'</p>' +
                                '<p class="fs075 cl-6666">'+orders[i].address+'</p>' +
                                '<div>' +
                                '<span class="weui-badge weui-badge_bd">距离约 '+getFlatternDistance(my_lat,my_lng,orders[i].lat,orders[i].lon).toFixed(0)+'m</span>' +
                                '<p class="msui_date">' +
                                '    <span class="cl-9999"> '+php_date("m月d日",orders[i].add_time)+'</span>' +
                                '    <span class="cl-9999"> '+php_date("H:i:s",orders[i].add_time)+'</span>' +
                                '</p>' +
                                '</div>' +
                                '</div>' +
                                '<span class="msui_tabCell-button">' +
                                '    <i class="micon-in"></i>' +
                                '</span>' +
                                '</a>';

                        html.push(h)
                    }

                    if (obj.page == 1) {
                        $("#box_orders").html(html.join(''));
                    } else {
                        $("#box_orders").append(html.join(''));
                    }

                    // 计算是否还有更多数据
                    if ((msg.data.total - (msg.data.current_page * msg.data.per_page)) > 0) {
                        obj.is_more = true;
                    }
                    obj.page++;
                }
            });
        }
    });


    var EARTH_RADIUS = 6378137.0;    //单位M
    var PI = Math.PI;

    function getRad(d){
        return d*PI/180.0;
    }

    function getFlatternDistance(lat1,lng1,lat2,lng2){
        var f = getRad((lat1 + lat2)/2);
        var g = getRad((lat1 - lat2)/2);
        var l = getRad((lng1 - lng2)/2);

        var sg = Math.sin(g);
        var sl = Math.sin(l);
        var sf = Math.sin(f);

        var s,c,w,r,d,h1,h2;
        var a = EARTH_RADIUS;
        var fl = 1/298.257;

        sg = sg*sg;
        sl = sl*sl;
        sf = sf*sf;

        s = sg*(1-sl) + (1-sf)*sl;
        c = (1-sg)*(1-sl) + sf*sl;

        w = Math.atan(Math.sqrt(s/c));
        r = Math.sqrt(s*c)/w;
        d = 2*w*a;
        h1 = (3*r -1)/2/c;
        h2 = (3*r +1)/2/s;

        var tmpReturn = d*(1 + fl*(h1*sf*(1-sg) - h2*(1-sf)*sg));
        return (tmpReturn?tmpReturn:0);
    }


    // 和PHP一样的时间戳格式化函数
    // @param  {string} format    格式
    // @param  {int}    timestamp 要格式化的时间 默认为当前时间
    // @return {string}           格式化的时间字符串
    function php_date ( format, timestamp ) {
        var a, jsdate=((timestamp) ? new Date(timestamp*1000) : new Date());
        var pad = function(n, c){
            if( (n = n + "").length < c ) {
                return new Array(++c - n.length).join("0") + n;
            } else {
                return n;
            }
        };
        var txt_weekdays = ["Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday"];
        var txt_ordin = {1:"st",2:"nd",3:"rd",21:"st",22:"nd",23:"rd",31:"st"};
        var txt_months = ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
        var f = {
            // Day
            d: function(){
                return pad(f.j(), 2);
            },
            D: function(){
                t = f.l(); return t.substr(0,3);
            },
            j: function(){
                return jsdate.getDate();
            },
            l: function(){
                return txt_weekdays[f.w()];
            },
            N: function(){
                return f.w() + 1;
            },
            S: function(){
                return txt_ordin[f.j()] ? txt_ordin[f.j()] : 'th';
            },
            w: function(){
                return jsdate.getDay();
            },
            z: function(){
                return (jsdate - new Date(jsdate.getFullYear() + "/1/1")) / 864e5 >> 0;
            },
            // Week
            W: function(){
                var a = f.z(), b = 364 + f.L() - a;
                var nd2, nd = (new Date(jsdate.getFullYear() + "/1/1").getDay() || 7) - 1;
                if(b <= 2 && ((jsdate.getDay() || 7) - 1) <= 2 - b){
                    return 1;
                } else{
                    if(a <= 2 && nd >= 4 && a >= (6 - nd)){
                        nd2 = new Date(jsdate.getFullYear() - 1 + "/12/31");
                        return date("W", Math.round(nd2.getTime()/1000));
                    } else{
                        return (1 + (nd <= 3 ? ((a + nd) / 7) : (a - (7 - nd)) / 7) >> 0);
                    }
                }
            },
            // Month
            F: function(){
                return txt_months[f.n()];
            },
            m: function(){
                return pad(f.n(), 2);
            },
            M: function(){
                t = f.F(); return t.substr(0,3);
            },
            n: function(){
                return jsdate.getMonth() + 1;
            },
            t: function(){
                var n;
                if( (n = jsdate.getMonth() + 1) == 2 ){
                    return 28 + f.L();
                } else{
                    if( n & 1 && n < 8 || !(n & 1) && n > 7 ){
                        return 31;
                    } else{
                        return 30;
                    }
                }
            },
            // Year
            L: function(){
                var y = f.Y();
                return (!(y & 3) && (y % 1e2 || !(y % 4e2))) ? 1 : 0;
            },
            //o not supported yet
            Y: function(){
                return jsdate.getFullYear();
            },
            y: function(){
                return (jsdate.getFullYear() + "").slice(2);
            },
            // Time
            a: function(){
                return jsdate.getHours() > 11 ? "pm" : "am";
            },
            A: function(){
                return f.a().toUpperCase();
            },
            B: function(){
                // peter paul koch:
                var off = (jsdate.getTimezoneOffset() + 60)*60;
                var theSeconds = (jsdate.getHours() * 3600) +
                        (jsdate.getMinutes() * 60) +
                        jsdate.getSeconds() + off;
                var beat = Math.floor(theSeconds/86.4);
                if (beat > 1000) beat -= 1000;
                if (beat < 0) beat += 1000;
                if ((String(beat)).length == 1) beat = "00"+beat;
                if ((String(beat)).length == 2) beat = "0"+beat;
                return beat;
            },
            g: function(){
                return jsdate.getHours() % 12 || 12;
            },
            G: function(){
                return jsdate.getHours();
            },
            h: function(){
                return pad(f.g(), 2);
            },
            H: function(){
                return pad(jsdate.getHours(), 2);
            },
            i: function(){
                return pad(jsdate.getMinutes(), 2);
            },
            s: function(){
                return pad(jsdate.getSeconds(), 2);
            },
            //u not supported yet
            // Timezone
            //e not supported yet
            //I not supported yet
            O: function(){
                var t = pad(Math.abs(jsdate.getTimezoneOffset()/60*100), 4);
                if (jsdate.getTimezoneOffset() > 0) t = "-" + t; else t = "+" + t;
                return t;
            },
            P: function(){
                var O = f.O();
                return (O.substr(0, 3) + ":" + O.substr(3, 2));
            },
            //T not supported yet
            //Z not supported yet
            // Full Date/Time
            c: function(){
                return f.Y() + "-" + f.m() + "-" + f.d() + "T" + f.h() + ":" + f.i() + ":" + f.s() + f.P();
            },
            //r not supported yet
            U: function(){
                return Math.round(jsdate.getTime()/1000);
            }
        };
        return format.replace(/[\\]?([a-zA-Z])/g, function(t, s){
            if( t!=s ){
                // escaped
                ret = s;
            } else if( f[s] ){
                // a date function exists
                ret = f[s]();
            } else{
                // nothing special
                ret = s;
            }
            return ret;
        });
    }

</script>

{/block}